package com.yhny.lykj.yuhannongye.Adapter;

import android.content.Context;
import android.content.res.Resources;
import android.net.Uri;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.longsichao.lscframe.view.LSCImageView;
import com.yhny.lykj.yuhannongye.R;
import com.yhny.lykj.yuhannongye.app.BaseRefreshListAdapter;
import com.yhny.lykj.yuhannongye.model.CarListModel;
import com.yhny.lykj.yuhannongye.tools.Tools;

import java.util.List;

/**
 * CarListAdapter
 * 购物车
 */
public class OrderInfoFromCarListAdapter extends BaseRefreshListAdapter<OrderInfoFromCarListAdapter.ViewHolder> {
    private List<CarListModel.ListEntity> list;
    private OnItemClickListener listener = null;
    private AdapterView.OnItemLongClickListener longlistener = null;
    private int selectedPosition = -1;// 选中的位置
    private Context mContext;
    private int num = 0;

    public OrderInfoFromCarListAdapter(List<CarListModel.ListEntity> list, Context context) {
        this.list = list;
        this.mContext = context;
    }

    @Override
    public void setOnItemClickListener(OnItemClickListener listener) {
        this.listener = listener;
    }


    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    protected void onBindBaseViewHolder(ViewHolder holder, int position) {
        final CarListModel.ListEntity entity = list.get(position);
//        holder.shopTv.setText(Tools.checkString(entity.goodsid));
//
//
//        holder.titleTv.setText("商品名称："+Tools.checkString(entity.goodsid));
//        holder.priceView.setText(""+entity.goodspay);
//        holder.numView.setText("商品数量:"+entity.goodsnum);
//        Resources resources = holder.shopTv.getContext().getResources();
//        int height = resources.getDimensionPixelOffset(R.dimen.item_image_small_width);
//        int width = resources.getDimensionPixelOffset(R.dimen.item_image_small_width);
//        String imageUrl = entity.p;
//        if (imageUrl == null) {
//            imageUrl = "";
//        }
//        if (!TextUtils.isEmpty(imageUrl)) {
//            holder.imgView.setPlaceHolder(R.drawable.normal_pic).setTargetSize(width, height).setImageURI(Uri.parse(imageUrl));
//        }else{
//            holder.imgView.setImageResource(R.drawable.normal_pic);
//        }

        final int pos = position;
        holder.checkView.setVisibility(View.GONE);

    }


    public void setSelectedPosition(int position) {
        selectedPosition = position;
    }
    @Override
    protected int getLayoutResId(int viewType) {
        return R.layout.item_car_list;
    }

    @Override
    protected ViewHolder onCreateBaseViewHolder(View itemView) {
        return new ViewHolder(itemView, listener);
    }



    public static class ViewHolder extends BaseRefreshListAdapter.ViewHolder {

        private TextView shopTv;
        private RelativeLayout groupView;
        private LSCImageView imgView;
        private TextView orderNumTv;
        private TextView titleTv;
        private TextView priceView;
        private TextView numView;
        private CheckBox checkView;

        public ViewHolder(View itemView, OnItemClickListener listener) {
            super(itemView, listener);
            groupView = (RelativeLayout)itemView.findViewById(R.id.item_car_group);
            shopTv = (TextView) itemView.findViewById(R.id.item_shop);
            imgView = (LSCImageView) itemView.findViewById(R.id.item_img1);
            orderNumTv = (TextView) itemView.findViewById(R.id.item_order_num);
            titleTv = (TextView) itemView.findViewById(R.id.item_title);
            priceView = (TextView) itemView.findViewById(R.id.item_price);
            numView = (TextView) itemView.findViewById(R.id.item_project_num);
            checkView = (CheckBox) itemView.findViewById(R.id.item_check);
        }

    }
}
